//
//  Date.swift
//  vgbox
//
//  Created by 宋海胜 on 2019/6/25.
//  Copyright © 2019 Swift Xcode. All rights reserved.
//

import Foundation
import SwiftDate

extension Date {
    
    // 秒转分秒
    static func secondsToMinSec(second: CGFloat) -> String {
        
        var sec: CGFloat = 0
        var min: CGFloat = 0
        var secStr: String = ""
        var minStr: String = ""
        
        if second < 3600 && 60 < second {
            min = second / 60
            sec = second.truncatingRemainder(dividingBy: 60)
            minStr = min > 9 ? String(format: "%d", Int(min)) : String(format: "0%d", Int(min))
            secStr = sec > 9 ? String(format: "%.f", sec) : String(format: "0%.f", sec)
            return String(format: "%@:%@", minStr, secStr)
        } else if second < 60 {
            sec = second.truncatingRemainder(dividingBy: 60)
            return sec > 9 ? String(format: "00:%.f", sec) : String(format: "00:0%.f", sec)
        }
        return "00:00"
    }
    
    func sy_toString(format: String) -> String {
        // 东八区
        let regin = Region(zone: Zones.asiaShanghai)
        // date 转string
        let dateStr = self.convertTo(region: regin).toFormat(format)
        return dateStr
    }
}
